// ==UserScript==
// @name         获取政府信息公开信息
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  政务公开要填写公开时间标题网址
// @author       You
// @match        http://www.yuxi.gov.cn/yxszfxxgk/*
// @icon         http://www.yuxi.gov.cn/r/public/yxs/www/img/favicon.ico
// @grant        none
// ==/UserScript==

function getMeta() {
    const title = document
      .querySelector(".ArticleTitle")
      .textContent.replace(/\s*/g, "");
    const about = document.querySelector(".ArticleAbout").textContent;
    const ind = about.indexOf("发布时间");
    const send_date = about.substring(ind + 5, ind + 24);
  
    const url = document.location.href;
    return `时间：${send_date}\n标题：${title}\n网址：${url}`;
  }
  
  function copyText(textToCopy) {
    const textArea = document.createElement("textarea");
    textArea.value = textToCopy;
    // 使text area不在viewport，同时设置不可见
    textArea.style.position = "absolute";
    textArea.style.opacity = 0;
    document.body.appendChild(textArea);
    textArea.focus();
    textArea.select();
    console.log("exec");
    if (document.execCommand("copy")) {
      textArea.remove();
      alert("已复制到剪贴板");
    }
  }
  (function () {
    "use strict";
  
    const res = getMeta();
    console.log("res", res);
  
    const btn = document.createElement("button");
    btn.textContent = "获取信息";
    btn.onclick = function () {
      copyText(res);
    };
  
    const about = document.querySelector(".ArticleAbout");
    about.appendChild(btn);
  
    // Your code here...
  })();
  